home *** CD-ROM | disk | FTP | other *** search
/ HAKERIS 11 / HAKERIS 11.ISO / linux / system / LinuxConsole 0.4 / linuxconsole0.4install-en.iso / guile0.4.lcm / share / guile / slib / chez.init < prev    next >
Encoding:
Text File  |  2004-01-06  |  12.3 KB  |  397 lines

  1. ;;;"chez.init" Initialization file for SLIB for Chez Scheme 6.0a -*-scheme-*-
  2. ;;; Authors: dorai@cs.rice.edu (Dorai Sitaram) and Aubrey Jaffer.
  3. ;;;
  4. ;;; This code is in the public domain.
  5.  
  6. ;;; Adapted to version 5.0c by stone@math.grin.edu (John David Stone) 1997
  7. ;;; Adapted to version 6.0a by Gary T. Leavens <leavens@cs.iastate.edu>, 1999
  8.  
  9. ;;; (software-type) should be set to the generic operating system type.
  10. ;;; UNIX, VMS, MACOS, AMIGA and MS-DOS are supported.
  11.  
  12. (define (software-type) 'UNIX)
  13.  
  14. ;;; (scheme-implementation-type) should return the name of the scheme
  15. ;;; implementation loading this file.
  16.  
  17. (define (scheme-implementation-type) 'chez)
  18.  
  19. ;;; (scheme-implementation-home-page) should return a (string) URL
  20. ;;; (Uniform Resource Locator) for this scheme implementation's home
  21. ;;; page; or false if there isn't one.
  22.  
  23. (define (scheme-implementation-home-page)
  24.   "http://www.cs.indiana.edu/chezscheme/")
  25.  
  26. ;;; (scheme-implementation-version) should return a string describing
  27. ;;; the version the scheme implementation loading this file.
  28.  
  29. (define (scheme-implementation-version) "6.0a")
  30.  
  31. ;;; (implementation-vicinity) should be defined to be the pathname of
  32. ;;; the directory where any auxillary files to your Scheme
  33. ;;; implementation reside.
  34.  
  35. (define implementation-vicinity
  36.   (lambda () "/usr/unsup/scheme/chez/"))
  37.  
  38. ;;; (library-vicinity) should be defined to be the pathname of the
  39. ;;; directory where files of Scheme library functions reside.
  40.  
  41. (define library-vicinity
  42.   (let ((library-path
  43.      (or
  44.       ;; Use this getenv if your implementation supports it.
  45.       (getenv "SCHEME_LIBRARY_PATH")
  46.       ;; Use this path if your scheme does not support GETENV
  47.       ;; or if SCHEME_LIBRARY_PATH is not set.
  48.       (case (software-type)
  49.         ((UNIX) "/usr/local/lib/slib/")
  50.         ((VMS) "lib$scheme:")
  51.         ((MS-DOS) "C:\\SLIB\\")
  52.         (else "")))))
  53.     (lambda () library-path)))
  54.  
  55. ;;; (home-vicinity) should return the vicinity of the user's HOME
  56. ;;; directory, the directory which typically contains files which
  57. ;;; customize a computer environment for a user.
  58.  
  59. (define home-vicinity
  60.   (let ((home-path (getenv "HOME")))
  61.     (lambda () home-path)))
  62.  
  63. ;;; *FEATURES* should be set to a list of symbols describing features
  64. ;;; of this implementation.  Suggestions for features are:
  65.  
  66. (define *features*
  67.   '(
  68.     source    ; Chez Scheme can load Scheme source files, with the
  69.           ;   command (slib:load-source "filename") -- see below.
  70.  
  71.     compiled  ; Chez Scheme can also load compiled Scheme files, with the
  72.           ;   command (slib:load-compiled "filename") -- see below.
  73.     rev4-report            ;conforms to
  74.     rev3-report            ;conforms to
  75.     ieee-p1178            ;conforms to
  76. ;    sicp                ;runs code from Structure and
  77.                     ;Interpretation of Computer
  78.                     ;Programs by Abelson and Sussman.
  79.     rev4-optional-procedures    ;LIST-TAIL, STRING->LIST,
  80.                     ;LIST->STRING, STRING-COPY,
  81.                     ;STRING-FILL!, LIST->VECTOR,
  82.                     ;VECTOR->LIST, and VECTOR-FILL!
  83. ;    rev2-procedures            ;SUBSTRING-MOVE-LEFT!,
  84.                     ;SUBSTRING-MOVE-RIGHT!,
  85.                     ;SUBSTRING-FILL!,
  86.                     ;STRING-NULL?, APPEND!, 1+,
  87.                     ;-1+, <?, <=?, =?, >?, >=?
  88.     multiarg/and-            ;/ and - can take more than 2 args.
  89.     multiarg-apply            ;APPLY can take more than 2 args.
  90.     rationalize
  91.     delay                ;has DELAY and FORCE
  92.     with-file            ;has WITH-INPUT-FROM-FILE and
  93.                     ;WITH-OUTPUT-FROM-FILE
  94.     string-port            ;has CALL-WITH-INPUT-STRING and
  95.                     ;CALL-WITH-OUTPUT-STRING
  96.     transcript            ;TRANSCRIPT-ON and TRANSCRIPT-OFF
  97.     char-ready?
  98.     macro                ;has R4RS high level macros
  99. ;    defmacro            ;has Common Lisp DEFMACRO
  100.     eval                ;R5RS two-argument eval
  101.     record                ;has user defined data structures
  102.     values                ;proposed multiple values
  103.     dynamic-wind            ;proposed dynamic-wind
  104. ;    ieee-floating-point        ;conforms to
  105.     full-continuation        ;can return multiple times
  106. ;    object-hash            ;has OBJECT-HASH
  107.  
  108.     sort
  109. ;    queue                ;queues
  110.     pretty-print
  111. ;    object->string
  112.     format
  113.     trace                ;has macros: TRACE and UNTRACE
  114. ;    compiler            ;has (COMPILER)
  115. ;    ed                ;(ED) is editor
  116.     system                ;posix (system <string>)
  117.     getenv                ;posix (getenv <string>)
  118. ;    program-arguments        ;returns list of strings (argv)
  119. ;    Xwindows            ;X support
  120. ;    curses                ;screen management package
  121. ;    termcap                ;terminal description package
  122. ;    terminfo            ;sysV terminal description
  123. ;    current-time            ;returns time in seconds since 1/1/1970
  124.     fluid-let
  125.     random
  126.     rev3-procedures
  127.     ))
  128.  
  129. ;;; (OUTPUT-PORT-WIDTH <port>) returns the number of graphic characters
  130. ;;; that can reliably be displayed on one line of the standard output port.
  131.  
  132. (define output-port-width
  133.   (lambda arg
  134.     (let ((env-width-string (getenv "COLUMNS")))
  135.       (if (and env-width-string
  136.            (let loop ((remaining (string-length env-width-string)))
  137.          (or (zero? remaining)
  138.              (let ((next (- remaining 1)))
  139.                (and (char-numeric? (string-ref env-width-string
  140.                                next))
  141.                 (loop next))))))
  142.       (- (string->number env-width-string) 1)
  143.       79))))
  144.  
  145. ;;; (OUTPUT-PORT-HEIGHT <port>) returns the number of lines of text that
  146. ;;; can reliably be displayed simultaneously in the standard output port.
  147.  
  148. (define output-port-height
  149.   (lambda arg
  150.     (let ((env-height-string (getenv "LINES")))
  151.       (if (and env-height-string
  152.            (let loop ((remaining (string-length env-height-string)))
  153.          (or (zero? remaining)
  154.              (let ((next (- remaining 1)))
  155.                (and (char-numeric? (string-ref env-height-string
  156.                                next))
  157.                 (loop next))))))
  158.       (string->number env-height-string)
  159.       24))))
  160.  
  161. ;;; (CURRENT-ERROR-PORT)
  162. (define current-error-port
  163.   (let ((port (console-output-port)))  ; changed from current-output-port
  164.     (lambda () port)))
  165.  
  166. ;;; (TMPNAM) makes a temporary file name.
  167. (define tmpnam
  168.   (let ((cntr 100))
  169.     (lambda ()
  170.       (set! cntr (+ 1 cntr))
  171.       (let ((tmp (string-append "slib_" (number->string cntr))))
  172.     (if (file-exists? tmp) (tmpnam) tmp)))))
  173.  
  174. ;;; (FILE-EXISTS? <string>) is built-in to Chez Scheme
  175.  
  176. ;;; (DELETE-FILE <string>) is built-in to Chez Scheme
  177.  
  178. ;; The FORCE-OUTPUT requires buffered output that has been written to a
  179. ;; port to be transferred all the way out to its ultimate destination.
  180. (define force-output flush-output-port)
  181.  
  182. ;;; "rationalize" adjunct procedures.
  183. (define (find-ratio x e)
  184.   (let ((rat (rationalize x e)))
  185.     (list (numerator rat) (denominator rat))))
  186. (define (find-ratio-between x y)
  187.   (find-ratio (/ (+ x y) 2) (/ (- x y) 2)))
  188.  
  189. ;;; CHAR-CODE-LIMIT is one greater than the largest integer which can
  190. ;;; be returned by CHAR->INTEGER.
  191. (define char-code-limit 256)
  192.  
  193. ;;; MOST-POSITIVE-FIXNUM is used in modular.scm
  194. ;; Chez's MOST-POSITIVE-FIXNUM is a thunk rather than a number.
  195.  
  196. (if (procedure? most-positive-fixnum)
  197.     (set! most-positive-fixnum (most-positive-fixnum)))
  198.  
  199. ;;; Return argument
  200. (define (identity x) x)
  201.  
  202. ;;; SLIB:EVAL is single argument eval using the top-level (user) environment.
  203. (define slib:eval eval)
  204.  
  205. ;;; define an error procedure for the library
  206. (define slib:error
  207.   (lambda args
  208.     (let ((cep (current-error-port)))
  209.       (if (provided? 'trace) (print-call-stack cep))
  210.       (display "Error: " cep)
  211.       (for-each (lambda (x) (display x cep)) args)
  212.       (error #f ""))))
  213.  
  214. ;;; define these as appropriate for your system.
  215. (define slib:tab #\tab)
  216. (define slib:form-feed #\page)
  217.  
  218. ;;; Support for older versions of Scheme.  Not enough code for its own file.
  219. ;;; last-pair is built-in to Chez Scheme
  220. (define t #t)
  221. (define nil #f)
  222.  
  223. ;;; Define these if your implementation's syntax can support it and if
  224. ;;; they are not already defined.
  225. ;;; 1+, -1+, and 1- are built-in to Chez Scheme
  226. ;(define (1+ n) (+ n 1))
  227. ;(define (-1+ n) (+ n -1))
  228. ;(define 1- -1+)
  229.  
  230. ;;; (IN-VICINITY <string>) is simply STRING-APPEND, conventionally used
  231. ;;; to attach a directory pathname to the name of a file that is expected to
  232. ;;; be in that directory.
  233. (define in-vicinity string-append)
  234.  
  235. ;;; Define SLIB:EXIT to be the implementation procedure to exit or
  236. ;;; return if exitting not supported.
  237. (define slib:chez:quit
  238.   (let ((arg (call-with-current-continuation identity)))
  239.     (cond ((procedure? arg) arg)
  240.       (arg (exit))
  241.       (else (exit 1)))))
  242.  
  243. (define slib:exit
  244.   (lambda args
  245.     (cond ((null? args) (slib:chez:quit #t))
  246.       ((eqv? #t (car args)) (slib:chez:quit #t))
  247.       ((eqv? #f (car args)) (slib:chez:quit #f))
  248.       ((zero? (car args)) (slib:chez:quit #t))
  249.       (else (slib:chez:quit #f)))))
  250.  
  251. ;;; For backward compatability, the SCHEME-FILE-SUFFIX procedure is defined
  252. ;;; to return the string ".scm".  Note, however, that ".ss" is a common Chez
  253. ;;; file suffix.
  254. (define scheme-file-suffix
  255.   (let ((suffix (case (software-type)
  256.           ((NOSVE) "_scm")
  257.           (else ".scm"))))
  258.     (lambda () suffix)))
  259.  
  260. ;;; (SLIB:LOAD-SOURCE "foo") should load "foo.scm" or with whatever
  261. ;;; suffix all the module files in SLIB have.  See feature 'SOURCE.
  262.  
  263. (define (slib:load-source f) (load (string-append f ".scm")))
  264.  
  265. ;;; (SLIB:LOAD-COMPILED "foo") should load the file that was produced
  266. ;;; by compiling "foo.scm" if this implementation can compile files.
  267. ;;; See feature 'COMPILED.
  268.  
  269. (define slib:load-compiled load)
  270.  
  271. ;;; At this point SLIB:LOAD must be able to load SLIB files.
  272.  
  273. (define slib:load slib:load-source)
  274.  
  275. ;;; The following make procedures in Chez Scheme compatible with
  276. ;;; the assumptions of SLIB.
  277.  
  278. ;;; Chez's sorting routines take parameters in the order opposite to SLIB's.
  279. ;;; The following definitions override the predefined procedures with the
  280. ;;; parameters-reversed versions.  See the SORT feature.
  281.  
  282. (define chez:sort sort)
  283. (define chez:sort! sort!)
  284. (define chez:merge merge)
  285. (define chez:merge! merge!)
  286.  
  287. (define sort
  288.   (lambda (s p)
  289.     (chez:sort p s)))
  290. (define sort!
  291.   (lambda (s p)
  292.     (chez:sort! p s)))
  293. (define merge
  294.   (lambda (s1 s2 p)
  295.     (chez:merge p s1 s2)))
  296. (define merge!
  297.   (lambda (s1 s2 p)
  298.     (chez:merge! p s1 s2)))
  299.  
  300. ;;; Chez's (FORMAT F . A) corresponds to SLIB's (FORMAT #F F . A)
  301. ;;; See the FORMAT feature.
  302.  
  303. (define chez:format format)
  304.  
  305. (define format
  306.   (lambda (where how . args)
  307.     (let ((str (apply chez:format how args)))
  308.       (cond ((not where) str)
  309.         ((eq? where #t) (display str))
  310.         (else (display str where))))))
  311.  
  312. ;; The following definitions implement a few widely useful procedures that
  313. ;; Chez Scheme does not provide or provides under a different name.
  314.  
  315. ;;; CALL-WITH-INPUT-STRING and CALL-WITH-OUTPUT-STRING are the string
  316. ;;; port versions of CALL-WITH-INPUT-FILE and CALL-WITH-OUTPUT-FILE.
  317. ;;; See the STRING-PORT feature.
  318.  
  319. (define call-with-output-string
  320.   (lambda (f)
  321.     (let ((outsp (open-output-string)))
  322.       (f outsp)
  323.       (let ((s (get-output-string outsp)))
  324.     (close-output-port outsp)
  325.     s))))
  326.  
  327. (define call-with-input-string
  328.   (lambda (s f)
  329.     (let* ((insp (open-input-string s))
  330.        (res (f insp)))
  331.       (close-input-port insp)
  332.       res)))
  333.  
  334. ;;; If your implementation provides R4RS macros:
  335. (define macro:eval slib:eval)
  336. ;;; macro:load also needs the default suffix.
  337. (define macro:load slib:load-source)
  338.  
  339. (define *defmacros*
  340.   (list (cons 'defmacro
  341.           (lambda (name parms . body)
  342.         `(set! *defmacros* (cons (cons ',name (lambda ,parms ,@body))
  343.                      *defmacros*))))))
  344. (define (defmacro? m) (and (assq m *defmacros*) #t))
  345.  
  346. (define (macroexpand-1 e)
  347.   (if (pair? e) (let ((a (car e)))
  348.           (cond ((symbol? a) (set! a (assq a *defmacros*))
  349.                      (if a (apply (cdr a) (cdr e)) e))
  350.             (else e)))
  351.       e))
  352.  
  353. (define (macroexpand e)
  354.   (if (pair? e) (let ((a (car e)))
  355.           (cond ((symbol? a)
  356.              (set! a (assq a *defmacros*))
  357.              (if a (macroexpand (apply (cdr a) (cdr e))) e))
  358.             (else e)))
  359.       e))
  360.  
  361. ;;; According to Kent Dybvig, you can improve the Chez Scheme init
  362. ;;; file by defining gentemp to be gensym in Chez Scheme.
  363. (define gentemp gensym)
  364.  
  365. (define base:eval slib:eval)
  366. (define (defmacro:eval x) (base:eval (defmacro:expand* x)))
  367. (define (defmacro:expand* x)
  368.   (require 'defmacroexpand) (apply defmacro:expand* x '()))
  369.  
  370. (define (slib:eval-load <pathname> evl)
  371.   (if (not (file-exists? <pathname>))
  372.       (set! <pathname> (string-append <pathname> (scheme-file-suffix))))
  373.   (call-with-input-file <pathname>
  374.     (lambda (port)
  375.       (let ((old-load-pathname *load-pathname*))
  376.     (set! *load-pathname* <pathname>)
  377.     (do ((o (read port) (read port)))
  378.         ((eof-object? o))
  379.       (evl o))
  380.     (set! *load-pathname* old-load-pathname)))))
  381.  
  382. (define (defmacro:load <pathname>)
  383.   (slib:eval-load <pathname> defmacro:eval))
  384.  
  385. (define slib:warn
  386.   (lambda args
  387.     (let ((cep (current-error-port)))
  388.       (if (provided? 'trace) (print-call-stack cep))
  389.       (display "Warn: " cep)
  390.       (for-each (lambda (x) (display x cep)) args))))
  391.  
  392. ;;; Load the REQUIRE package.
  393.  
  394. (slib:load (in-vicinity (library-vicinity) "require"))
  395.  
  396. ;; end of chez.init
  397.